package net.myspring.middle.domain;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import net.myspring.common.domain.TreeEntity;
import net.myspring.common.mybatis.provider.annotation.Entity;
import net.myspring.common.mybatis.provider.annotation.Table;
import org.springframework.data.annotation.Transient;

/**
 * Created by liuj on 16/7/10.
 */
@Entity
@Table(name="sys_menu")
public class Menu extends TreeEntity<Menu> {

    public enum MenuType {
        NAVIGATION_GROUP("导航分组", 10),
        NAVIGATION("导航菜单", 20),
        FUNCTION("功能菜单", 30);
        private static BiMap<String, Integer> map;

        private MenuType(String name, Integer value) {
            this.name = name;
            this.value = value;
        }

        private String name;
        private Integer value;

        public String getName() {
            return name;
        }

        public Integer getValue() {
            return value;
        }

        public static BiMap<String, Integer> getMap() {
            if (map == null) {
                map = HashBiMap.create();
                for (MenuType menuType : MenuType.values()) {
                    map.put(menuType.getName(), menuType.getValue());
                }
            }
            return map;
        }
    }

    private String name;
    private String code;
    private Integer type;
    private Boolean hidden;
    private String link;
    private String icon;
    private Integer sort;
    @Transient
    private String fullName;

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Boolean getHidden() {
        return hidden;
    }

    public void setHidden(Boolean hidden) {
        this.hidden = hidden;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public String getTypeLabel() {
        return MenuType.getMap().inverse().get(type);
    }
}